﻿var curPlayer=null;
//声音控制
var testBarP = {
      mdivTrack:function (){return document.getElementById("track");},
      mdivBar:function (){return document.getElementById("trackBar");},
      mdivNow:function (){return document.getElementById("trackNow");},
      sliderType:"P",
      draging:false,
      GetPos : function()
      {
            return this.mdivBar().style.left;
      },
      SetPos : function(pos)
      {
            var tempBar = this.mdivBar();
            tempBar.style.left = pos;
            tempBar = null;
      },
      SetNow : function(pos)
      {
            var tempBar = this.mdivNow();
            tempBar.style.width = pos;
            tempBar = null;
      },
      Init:function()
      {
            var tempBar = this.mdivBar();
            tempBar.onmousedown = BeforeDragP;
            tempBar = null;
      }
}
var testBarV = {
      mdivTrack:function (){return document.getElementById("volumeTrack");},
      mdivBar:function (){return document.getElementById("volumeBar");},
      mdivNow:function (){return document.getElementById("volumeNow");},
      sliderType:"V",
      draging:false,
      GetPos : function()
      {
            return this.mdivBar().style.left;
      },
      SetPos : function(pos)
      {
            var tempBar = this.mdivBar();
            tempBar.style.left = pos;
            tempBar = null;
      },
      SetNow : function(pos)
      {
            var tempBar = this.mdivNow();
            tempBar.style.width = pos;
            tempBar = null;
      },
      Init:function()
      {
            var tempBar = this.mdivBar();
            tempBar.onmousedown = BeforeDragV;
            tempBar = null;
      }
}
function BeforeDragV()
{
    if (event.button != 1)
    {
        return;
    }
    testBarV.draging = true;
    testBarP.draging = false;
}
function BeforeDragP()
{
    if (event.button != 1)
    {
        return;
    }
    testBarV.draging = false;
    testBarP.draging = true;
}

//拖拽中
function OnDrag()
{
    var bar = null;
    if((typeof(testBarV)!="undefined") && (testBarV!=null) && testBarV.draging)//声音条在拖动
    {
        var phyPos = event.clientX - testBarV.mdivTrack().offsetLeft-4;//变化的位置
        var max = testBarV.mdivTrack().offsetWidth;
        if(phyPos<0)phyPos = 0;
        if(phyPos>max) phyPos = max;
        var percent = ''+ phyPos/max*100 +'%';
        testBarV.SetNow(percent);
        testBarV.SetPos(percent);
        curPlayer.SetVolume(percent);
    }
    else if((typeof(testBarP)!="undefined") && (testBarP!=null) && testBarP.draging)
    {
        var phyPos = event.clientX - testBarP.mdivTrack().offsetLeft-4;//变化的位置
        var cache =  testBarP.mdivNow().offsetWidth;
        var max = testBarP.mdivTrack().offsetWidth;
        if(phyPos<0)phyPos = 0;
        //if(phyPos>cache) phyPos = cache;
        var percent = ''+ phyPos/max*100 +'%';
        testBarP.SetPos(percent);
        curPlayer.SetPos(phyPos/max);
    }
    else
        return;
}
//结束拖拽
function EndDrag()
{
    testBarV.draging = false;
    testBarP.draging = false;
}
document.onmousemove = OnDrag;
document.onmouseup = EndDrag;
document.onkeydown = function(){return false;};
document.onselectstart=function(){return false;};